<template>
  <div>
    <!--页头-->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>新的订单</el-breadcrumb-item>
    </el-breadcrumb>
    <order-list
        :order="order"
        @handleCurrentChange="handleCurrentChange"
        @handleSizeChange="handleSizeChange"
        @receive="receive"
        @send="send"
    ></order-list>
  </div>

</template>

<script>
import OrderList from "../../components/OrderList";

export default {
  name: "LatestOrder",
  components: {OrderList},
  inject: ['reload'],

  data() {
    return {
      order: {
        orderMsg: [],
        queryInfo: {
          query: '',
          pagenum: 1,
          pagesize: 4
        },
        total: 0
      }

    }
  },
  created() {
    this.getLatestorderList();
  },
  methods: {
    getLatestorderList() {
      this.$axios({
        method: "get", url: "/order/latestorder",
        params: {
          rid: this.$store.getters.rid,
          query: this.order.queryInfo.query,
          pagenum: this.order.queryInfo.pagenum,
          pagesize: this.order.queryInfo.pagesize,
          userId:this.$store.getters.uid,
        }
      }).then(response => {
        if (response.data.success) {
          this.order.orderMsg = response.data.latest_order_list;
          this.order.total = response.data.total;
        }
      })
          .catch(error => console.log(error))
    },

    handleSizeChange(data) {
      this.queryInfo = data
      this.getLatestorderList()
    },
    //监听 页码值 改变事件
    handleCurrentChange(data) {
      this.queryInfo = data
      this.getLatestorderList()
    },
    //  接单
    receive(id) {
      this.$axios({
        method: "get",
        url: "/order/receive",
        params: {
          id: id
        }
      })
          .then(response => {
            this.getLatestorderList()
          })
          .catch(error => console.log(error))
    },
    //  配送
    send(id) {
      this.$axios({
        method: "get",
        url: "/order/send",
        params: {
          id: id
        }
      }).then(response => {
        this.getLatestorderList()
      })
          .catch(error => console.log(error))
    }
  }

}
</script>

<style scoped>

</style>
